package com.situ.lession1226.controller;


import com.situ.lession1226.model.News;
import com.situ.lession1226.model.Rating;
import com.situ.lession1226.service.NewsService;
import com.situ.lession1226.service.RatingService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Map;

//返回一个电影页面

@Controller

public class OneNewsController {
    private NewsService newsService;
    private RatingService ratingService;

    public OneNewsController(NewsService newsService,RatingService ratingService) {
        this.newsService = newsService;
        this.ratingService=ratingService;

    }
//
//    public OneNewsController(NewsService newsService) {
//        this.newsService = newsService;
//    }


    @GetMapping("/onenews")
    public String technology(Integer newid,Map<String,Object>map){
        News news=newsService.findById(newid);
        Rating rating=ratingService.findById(newid);
        if (news == null) {
            map.put("error", "要点击的电影不存在");
        } else {
            map.put("news", news);
            if(rating==null){
                map.put("rating","暂无评分");
            }else {
                map.put("rating",""+String.format("%.2f", rating.score));
            }
        }
        return "/onenews/onenews";
    }
}
